package com.stone.im.geteway.websocket;

import io.netty.channel.socket.SocketChannel;

/**
 * 消息推送
 */
public class PushManager {

    public void start(){
        new PushThread().start();
    }

    class PushThread extends Thread {

        @Override
        public void run() {

            while (true){
                try {
                    Thread.sleep(60* 1000);

                    String userId="test001";

                    NettyChannelManager nettyChannelManager = NettyChannelManager.getInstance();

                    SocketChannel channel = nettyChannelManager.getChannel(userId);

                    if (channel!=null){
                        channel.writeAndFlush("推送一条消息");
                    }else{
                        System.out.println("目标用户已下线");
                    }

                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}